package javaclass.trouble;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test {
    private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(50, 51,
            1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(500),
            new ThreadPoolExecutor.CallerRunsPolicy());
//    private static ThreadPoolExecutor threadPool2 = new ThreadPoolExecutor(1, 2,
//            1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(500),
//            new ThreadPoolExecutor.CallerRunsPolicy());
    
    public static void main(String[] args) {
        int c = 0;
        System.out.println("go");
//        threadPool.execute(new Runnable() {
//            @Override
//            public void run() {
//                while(true){
//                    ServiceA sa = ServiceA.s;
//                    if(sa != null) {
//                        System.out.println("not null");
//                        ServiceA.s.ses[99999].say();
//                        break;
//                    }
//                }
//            }
//        });
        for (int i = 1; i <= 50; i++) {
            final int fi = i;
            threadPool.execute(new Runnable() {
                @Override
                public void run() {
                    ServiceA a = ServiceA.get(fi);
                    a.ses[99999].say();
                    System.out.println(a);
//                    ServiceA b = a;
//                    System.out.println(b);
                }
            });
//            if(i == 30 && c < 10) {
//                try {
//                    Thread.sleep(2000);
//                    System.out.println("----------");
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                i=1;
//                ServiceA.init();
//                c++;
//            }
        }
    }
}

class MyThread implements Runnable {
    @Override
    public void run() {
    }
}